import java.util.Arrays;
import java.util.Scanner;


//————————————————————————————题目目录——————————————————————————————————
//1.打印 X 图形
//2.（用方法的形式）计算1！+2！+3！+4！+5！的值
//3.（递归）顺次输出一个数的每一位
//4.（递归）求 1+2+3+4+5+6+7+8+9+10的和
//5.（递归）输入一个非负整数，返回输入组成它的数字之和
     //如：输入1729，返回1+7+2+9=19
//6.（递归）斐波那契数列
//6s.（循环）斐波那契数列

// 数组的初始化的三种形式
// 遍历数组的两种形式

//7.使用函数求最大值
//8. 求 n的阶乘（同 2.）
//9.求斐波那契数列的第n项。(迭代实现) (同6s.)
//10. (递归 )求 n的阶乘
//11.跳台阶


//借助工具Arrays来输出数组
//12.模拟实现ToString
//借助工具类Arrays来复制数组
//13.顺序查找
//14.二分查找
//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class Main {

        /*//1.打印 X 图形
        //思路 遇到i==j和i+j==n的时候是“*”
        //第二次错误！！要求多次输入1！！！

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext())
        {
            int n = scanner.nextInt();

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    if(i == j || i + j == (n-1))//第一次错误！！在这里是 ==（n-1）！！
                    {
                        System.out.print("*");
                    } else  {
                        System.out.print(" ");
                    }
                    //第一次错误！！把换行的代码敲在这一行了！
                }
                System.out.println();
            }
        }*/


    /*    //2.（用方法的形式）计算1！+2！+3！+4！+5！的值
      //求n的阶乘
    public static int func(int n)
        {
            int ret = 1;
            for (int i = 1; i <= n; i++) {
                ret *= i;
            }
            return ret;
        }
     //求n阶乘的和的值
    public static int Sum(int n){
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
            sum += func(i);
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(Sum(5));
    }*/

    //————————————————————递归练习————————————————————————————————————

    /*//3.（递归）顺次输出一个数的每一位
    public static void print(int n){
        if(n < 10){
            System.out.println(n);
            return;
        }else {
            print(n / 10);
            System.out.println(n % 10);//最后一个递先输出
        }
    }
    public static void main(String[] args) {
        print(123);
    }*/

    /*//4.（递归）求 1+2+3+4+5+6+7+8+9+10的和
    public static int sum(int n){

        if(n==1){
            return n;
        }
        return n + sum(n-1);

    }
    public static void main(String[] args) {
        System.out.println(sum(10));
    }*/

    /*//5.（递归）输入一个非负整数，返回输入组成它的数字之和
    //如：输入1729，返回1+7+2+9=19
    public static int sum(int n){
        if(n<10){
            return n;
        }
        return sum(n/10)+(n%10);

    }

    public static void main(String[] args) {
        System.out.println(sum(1729));
    }*/

    /*//6.（递归）斐波那契数列
    public static int fib(int n){
        if(n==1)
            return 0;
        if(n==2)
            return 1;
        return fib(n-1)+fib(n-2);
    }

    //6s.（循环）斐波那契数列
    public static int fib2(int n){
        int a = 0;
        int b = 1;
        int c = 0;
        for (int i = 3; i <= n; i++) {
            c = a + b;
            a = b;
            b = c;
        }
        return c;
    }

    public static void main(String[] args) {
        System.out.println(fib(10));
        System.out.println(fib2(10));
    }
*/

    /*//数组的初始化的三种形式
    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 4};
        int[] arr2 = new int[4];
        int[] arr3 = new int[]{1, 2 ,3, 4};
        System.out.println(arr1);
        System.out.println(arr2);
        System.out.println(arr3);
    }*/

    /*//遍历数组的两种形式
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7,8,9};

        //有下标的依赖
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }

        System.out.println();

        //单纯只需要打印数组数据
        for(int x:arr){
            System.out.print(x+" ");
        }
    }*/


    /*//8. 求 n的阶乘
    public static int ret(int n){
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }
    public static int sum(int n){
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += ret(i);
        }
        return sum;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(sum(n));
    }*/

    /*//9.求斐波那契数列的第n项。(迭代实现)
    public static int fib(int n) {
        int fib1 = 0;
        int fib2 = 1;
        int fib3 = 0;
        for (int i = 2; i <= n ; i++) {
            fib3 = fib1 + fib2;
            fib1 = fib2;
            fib2 = fib3;
        }
        return fib3;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fib(n));

    }*/

    /*//10. (递归 )求 n的阶乘
    public static int ret (int n){
        int ret = 1;
        if(n==1){
            return 1;
        }
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret(n-1)+ ret;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(ret(n));
    }*/

     /*//11.跳台阶
    public static int target(int n){
        if(n==1){
            return 1;
        } else if (n==2) {
            return 2;
        }else {
            return target(n-1)+target(n-2);
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(target(n));
    }*/

    /*//借助工具Arrays来输出数组
    public static int[] arr(){
        return new int[10];
    }
    public static void main(String[] args) {
        int[] ret = arr();
        //这是将参数数组，转换为字符串输出
        System.out.println(Arrays.toString(ret));
    }
*/
    /*//12.模拟实现ToString
    public static String array(int[] arr){
        String ret = "[";
        for (int i = 0; i < arr.length; i++) {
            ret += arr[i];
            if(i< arr.length-1){
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        String s = array(arr);
        System.out.println(s);
    }*/

    /*//运用工具类Arrays来复制数组

    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        //方法1 直接暴力复制循环
        int[] copy = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copy[i] = array[i];
        }
        //方法2 运用工具类1
        int[] copy = Arrays.copyOf(array,array.length);
        System.out.println(Arrays.toString(copy));
        //同时,多*2，等于给array扩容了
        int[] copy2 = Arrays.copyOf(array,array.length*2);
        //方法3 工具类2
        //如果要拷贝指定范围内的，则如下
        //但是如下的范围为 [ , )
        int[] copy3 = Arrays.copyOfRange(array,1,3);

        //方法4 工具类4
        //            被拷贝的  起始位置 目的数组 目的的起始位置  拷贝长度
        System.arraycopy(array,0,copy,0,array.length);

    }*/

    /*//再敲一遍学的工具类
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(Arrays.toString(array));

        int[] array2 = Arrays.copyOf(array,array.length);
        int[] array3 =Arrays.copyOfRange(array,1,3);
        int[] array4 = new int[10];
        System.arraycopy(array,0,array4,0,array.length);
    }*/


    /*//13.顺序查找
    public static int found(int[] arr,int n){
        for (int i = 0; i < arr.length; i++) {
            if(n==arr[i])
            {
                return i;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] array = new int[]{1,2,3,4,5};
        int ret = found(array,4);
        if(ret >= 0)
        {
            System.out.println(array[ret]);
        }
    }*/

    /*//14.二分查找
    public static int found(int[] array,int n)
    {
        int left = 0;
        int right = array.length-1;
        //mid的定义不能放在这一行！！！
        while (left<=right){
            int mid = (left + right)/2;//要放进循环！！！
            if(array[mid]>n){
                right = mid-1;
            } else if (array[mid]<n) {
                left = mid+1;
            }else {
                return mid;
            }
        }
         return -1;



    }

    public static void main(String[] args) {
        int[] array = {1,5,7,8,9,12,16,22,24};



        if(array[found(array,22)] >= 0){
            System.out.println(array[found(array,22)]);
            System.out.println(found(array, 22));
        }else{
            System.out.println("对不起没找到！");
        }

    }*/

    /*//JAVA自带的工具！
    public static void main(String[] args) {
        int[] array = new int[]{1,2,7,4,3,5,6};
        int[] array2 = new int[]{1,2,7,4,3,5,6};
        //排序 Arrays.sort
        Arrays.sort(array);
        //查找 Arrays.binarySearch
        System.out.println(Arrays.binarySearch(array, 6));
        //比较 Arrays.equals
        System.out.println(Arrays.equals(array2, array));
        //填充数据 Arrays.fill
        int[] array3 = new int[10];
        Arrays.fill(array3,-1);
        Arrays.fill(array3,1,3,-1);//下标为 [1,3) 填充-1，其他的还是原始的0
        System.out.println(array3[0]);
    }*/

    //15.冒泡排序
    //16.数组逆置

    /*//二维数组的3种初始化形式
    int[][] array1 = {{1,2,3},{4,5,6}};
    int[][] array2 = new int[][]{{1,2,3},{4,5,6}};
    int[][] array3 = new int[2][3];

    //二维数组的遍历
    public static void main(String[] args) {
        int[][] array1 = {{1,2,3},{4,5,6}};
        //normal型
        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j < array1[i].length; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
        //工具类的应用
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.deepToString(array1));
    }*/

}